package reflect;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;


public class Test2 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");
        Method[] methods = cls.getMethods();
        Object obj = cls.newInstance();
        for (Method m : methods){
            if(m.getModifiers()== Modifier.PUBLIC && m.getParameterCount()==0){//获取public方法并且参数个数为0
                System.out.println("调用"+ m.getName()+"方法");
                m.invoke(obj);
            }
        }
    }
}
